import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from numpy import fft
from IPython.html import widgets
%matplotlib inline
cv2.cornerHarris()
: cornerHarris(src, blockSize, ksize, k[, dst[, borderType]]) -> dstsudoku = cv2.imread("public-images/fish.png")[:,:,::-1]
gray_sudoku = cv2.cvtColor(sudoku, cv2.COLOR_RGB2GRAY)
plt.imshow(gray_sudoku, cmap = plt.cm.gray)
<matplotlib.image.AxesImage at 0x7fda56efcad0>
corners = cv2.cornerHarris(gray_sudoku, 2, 3, 0.0001)
corners = cv2.dilate(corners, np.ones((5, 5)))
corners = corners >= 0.0001*corners.max()
## dilate to make it more visible
img = sudoku.copy()
img[corners] = (255, 0, 0)
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7fda56e22450>
def plot_corner(k):
corners = cv2.cornerHarris(gray_sudoku, 2, 3, k = 10**k)
corners = cv2.dilate(corners, np.ones((5, 5)))
corners = corners >= 0.0001*corners.max()
plt.imshow(corners)
widgets.interact(plot_corner, k = (-5, 2, 0.1))
corners = cv2.goodFeaturesToTrack(gray_sudoku, 15, 0.1, 100, )
img = sudoku.copy()
for c in corners[:,:,:]:
x, y = map(int, c[0])
img = cv2.circle(img, (x, y), 10, color = (0, 255, 0), thickness = -1)
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7fda568c68d0>